using System.ComponentModel;
using System.Xml.Serialization;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;

using Tomahawk.Runtime.Physics.Descriptors;

namespace Tomahawk.Processors
{
    [ContentProcessor(DisplayName = "Collision Processor - Tomahawk Engine")]
    public class CollisionContentProcessor : ContentProcessor<PhysicsActorDesc, PhysicsActorDesc>
    {
        protected string name;
        protected PhysicsActorType type;

        [DisplayName("Name")]
        [DefaultValue("Undefined")]
        [Description("Name of the actor")]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        [DisplayName("Type")]
        [DefaultValue("StaticActor")]
        [Description("Type of physics simulation asigned to this actor")]
        public PhysicsActorType Type
        {
            get { return type; }
            set { type = value; }
        }

        public override PhysicsActorDesc Process(PhysicsActorDesc input, ContentProcessorContext context)
        {
            input.type = type;
            input.name = name;
            return input;
        }
    }

    [ContentTypeWriter]
    class CollisionWriter : ContentTypeWriter<PhysicsActorDesc>
    {
        protected override void Write(ContentWriter output, PhysicsActorDesc value)
        {
            XmlSerializer x = new XmlSerializer(typeof(PhysicsActorDesc));
            x.Serialize(output.BaseStream, value);
        }
        public override string GetRuntimeType(TargetPlatform targetPlatform)
        {
            return typeof(PhysicsActorDesc).AssemblyQualifiedName;
        }
        public override string GetRuntimeReader(TargetPlatform targetPlatform)
        {
            return "Tomahawk.Runtime.ContentLoaders.CollisionReader, " +
                "Tomahawk.Runtime, Version=1.0.0.0, Culture=neutral";
        }
    }
}